<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      th:replace="header">
<div th:fragment="content">

<!-- 模板列表 -->

    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-header">
                    <h4>模板列表</h4>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-bordered table-striped table-vcenter" style="text-align: center" >
                            <thead>
                            <tr >
                                <th style="text-align: center;width: 100px" >模板ID</th>
                                <th style="text-align: center" >模板名称</th>
                                <th style="text-align: center" >模板设计人</th>
                                <th style="text-align: center" >最后修改日期</th>
                                <th style="text-align: center"  >操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr th:each="template : ${templates.getRecords()}" th:id="'template-'+${template.getTemplateId()}">
                                <td th:text="${template.getTemplateId()}" style="text-align: center">templateId</td>
                                <td th:text="${template.getTemplateName()}">templateName</td>
                                <td th:text="${template.getTname()}">tname</td>
                                <td><code th:text="${#dates.format(template.getGmtModified(), 'yyyy-MM-dd HH:mm:ss')}">gmtModified</code></td>
                                <td>
                                    <div class="btn-group">
                                        <a class="btn btn-xs btn-info" th:href="'/Template/Edit/'+${template.getTemplateId()}" title="编辑" data-toggle="tooltip"><i class="mdi mdi-pencil"></i></a>

                                        <a style="margin-left: 12px" class="btn btn-xs btn-danger"  th:href="'javascript:delAjax(\''+${template.getTemplateId()}+'\')'" title="删除" data-toggle="tooltip"><i class="mdi mdi-window-close"></i></a>
                                    </div>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                    <!-- 分页码 -->
                    <ul class="pagination">
                        <!-- 第一页按钮 -->
                        <li th:class="${templates.hasPrevious()?'':'disabled'}" >
                            <a th:href="${templates.hasPrevious()?('/Template/List?p='+(templates.getCurrent()-1)):'javascript:return false;'}">«</a>
                        </li>
                        <!-- 中间按钮 -->
                        <li th:each="i : ${#numbers.sequence(
                        (templates.getCurrent()>3?template.getCurrent()-2:1)
                        , (templates.getCurrent()<(templates.getPages()-2)?templates.getCurrent()+2:templates.getPages())
                        )}"
                            th:class="${templates.getCurrent()==i?'active':''}"
                        >
                            <a th:href="'/Template/List?p='+ ${i}"
                               th:text="${i}"
                            >???</a>
                        </li>
                        <!-- 最后一页按钮 -->
                        <li  th:class="${templates.hasNext()?'':'disabled'}" >
                            <a th:href="${templates.hasNext()?('/Template/List?p='+(templates.getCurrent()+1)):'javascript:return false;'}">»</a>
                        </li>
                        <li><span th:text="'共 '+ ${templates.getCurrent()} +' / '+ ${templates.getPages()} +' 页' ">共 0 / 0 页</span></li>
                    </ul>
                </div>
            </div>
        </div>
    </div>


<script type="text/javascript">
    function delAjax(id) {
        lightyear.loading("show")
        $.ajax({
            type: "POST",
            url: "/Template/Del",
            dataType: "json",
            data: {
                "templateId": id,
            },
            success: function (data, status) {
                console.log(data)
                lightyear.loading('hide');
                if (status === "success") {
                    if (data.code === 200){
                        lightyear.notify('您成功删除了一个模板~', 'success', 1000);
                        $("#template-" + id).remove();
                    } else{
                        console.log("后端拒绝")
                        lightyear.notify(data.msg, 'danger', 3000);
                    }
                }else{
                    console.log("网络问题")
                    lightyear.notify('网络不可用，请稍候再试！！！', 'danger', 3000);
                }
            },
            error: function (xhr, errorText, errorType) {
                lightyear.loading('hide');
                lightyear.notify('服务器错误，请稍后再试~', 'danger', 2000);
            }
        });
    }
</script>
</div>
</html>